package lily.phs.urh;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import lily.phs.child.ChildScrollActivity;
import lily.phs.child.ImageList;
import lily.phs.database.Constants;
import lily.phs.diabet.DiabeterDetails;
import lily.phs.entertain.YuleActivity;
import lily.phs.epidemic.EpidemicList;
import lily.phs.healthedu.HealthMain;
import lily.phs.mental.MentalerDetails;
import lily.phs.object.DiabetService;
import lily.phs.object.EpidemicRecord;
import lily.phs.object.FirstPrenatalVisit;
import lily.phs.object.HealthTest;
import lily.phs.object.HereTipa;
import lily.phs.object.HospitalHistory;
import lily.phs.object.HuiZhenRecord;
import lily.phs.object.JieZhenRecord;
import lily.phs.object.LastPostnatalCheck;
import lily.phs.object.MedicateRecord;
import lily.phs.object.MentalerInfo;
import lily.phs.object.ModuleSelect;
import lily.phs.object.NewBornChild;
import lily.phs.object.NonimmuneVaccineHistory;
import lily.phs.object.OneChild;
import lily.phs.object.PersonInfo;
import lily.phs.object.PostnatalVisit;
import lily.phs.object.PrenatalVisit;
import lily.phs.object.SickbedHistory;
import lily.phs.object.ThreeChild;
import lily.phs.object.TwoChild;
import lily.phs.object.VaccinationCard;
import lily.phs.object.VaccinationRecord;
import lily.phs.object.VisitMentals;
import lily.phs.pregnance.PregnantScrollActivity;
import lily.phs.urh.R;
import lily.phs.vaccination.VaccinationScrollActivity;
import lily.ui.control.AccountExpandablebaseadapter;
import lily.ui.control.MyPopupWindow;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.InputType;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;


public class PeopleScrollActivity extends Activity implements OnClickListener,Constants{
	
	public final static String FATHERACCOUNT = "fatherAccount";
	public final static String CHILDACCOUNT = "childAccount";
	AlertDialog ad;
	MyPopupWindow mPopupWindow;
	
	private static final String TAG = "IsmsMainActivity";
	public static final String FIRST_INTENT_TAG = "first";
	public static final String SECOND_INTENT_TAG = "second";
	public static final String THIRD_INTENT_TAG = "third";
	public static final String FOUR_INTENT_TAG = "four";
	public static final String FIVE_INTENT_TAG = "five";
	public static final String SIX_INTENT_TAG = "six";
	public static final String SEVEN_INTENT_TAG = "seven";
	public static final String EIGHT_INTENT_TAG = "eight";
	public static final String NINE_INTENT_TAG = "nine";
	public static final String TEN_INTENT_TAG = "ten";
	public static final String ELEVEN_INTENT_TAG = "eleven";
	public static final int FIRST_VIEW = 0;
	public static final int SECOND_VIEW = 1;
	public static final int THIRD_VIEW = 2;
	public static final int FOUR_VIEW = 3;
	public static final int FIVE_VIEW = 4;
	public static final int SIX_VIEW = 5;
	public static final int SEVEN_VIEW = 6;
	public static final int EIGHT_VIEW = 7;
	public static final int NINE_VIEW = 8;
	public static final int TEN_VIEW = 9;
	public static final int ELEVEN_VIEW = 10;
	
	private static final String[] PROJECTION = new String[]{HETE_COLUMN2};//依次取得对应的用户的ID，档案ID，档案名称
	private static final String[] PROJECTION1 = new String[]{THRE_DATE};
	private static final String[] PROJECTION2 = new String[]{CORE_DATE};
	private static final String[]  table={"健康档案","个人基本信息","健康体检","接诊记录","会诊记录"};
	person_info pi1;
	person_info2 pi2;
	HealthTest_1 ht_1;
	HealthTest_2 ht_2;
	HealthTest_3 ht_3;
	HealthTest_4 ht_4;
	HealthTest_5 ht_5;
	HealthTest_6 ht_6;
	PerHealthFirstView phfv;//封面
	JiezhenView jzv;
	HuizhenView hzv;
	
	ScrollPeopleLayout mRoot;
	private int profileid,father,call;
	Button leftBtn;
    Button rightBtn ;
    Button rightBtn2,rightBtn0;
    private int pageIndex;
    private ProgressDialog mpDialog;
    List<String> accountFather;

	List<List<Map<String, String>>> accountChild;
    AccountExpandablebaseadapter adapter;
	ExpandableListView listAccount;
	JieZhenRecord jzr;
	HuiZhenRecord hzr;
	
	List<Map<String, String>> cashAccount2,cashAccount1;
	HereTipa ht;
	private GridView gvModule;
	private ArrayList<Map<String,Object>> items; 
	
	private int healthtest_num=0,jiezhen_num=0,huizhen_num=0;
	
	private int[] image ={R.drawable.child_1,R.drawable.child_2,R.drawable.child_3,R.drawable.child_4,R.drawable.child_4};    
    //private String[] name={"Record","Reminder","Education","Setting","Help"};
    private String[] name={"健康档案封面","个人基本信息表","体检表-2011-7-25","接诊记录表-2011-7-25","会诊记录表-2011-7-25"};
    private int[] imageOfInitialModuels={
    		R.drawable.health_education,
    		R.drawable.yiqingshangbao,
    		R.drawable.yufangjiezhong,
    		R.drawable.entertain,
    		R.drawable.health_education};
    private String[] nameOfInitialModuels={
    		"健康教育",
    		"传染病疫情上报管理",
    		"预防接种",
    		"寓教于乐",
    		"卫生监督"};
    private int[] idOfInitialModuels = {
    		MODULE_HEALTH_EDU,MODULE_EPIDEMIC,MODULE_VACCINATION,MODULE_ENTERTANCE,MODULE_SUPERVISE};

    
    public Handler mHandler = new Handler(){
    	@Override
    	public void handleMessage(Message msg) {
    		
    		super.handleMessage(msg);
    		switch(msg.what){
        	case 0:
        		rightBtn0.setText("删除");
        		rightBtn0.setVisibility(View.VISIBLE);
        		break;
        	case 1:
        	case 2:
        		rightBtn0.setText("修改");
        		rightBtn0.setVisibility(View.VISIBLE);
        		break;
        	case 3:
        	case 4:
        	case 5:
        	case 6:
        	case 7:
        	case 8:
        	case 9:
        	case 10:
        		rightBtn0.setText("新建");
        		rightBtn0.setVisibility(View.VISIBLE);
        		break;
        	}
    	}
    };
    
    @Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
	}
    
    @Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.people_main);
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.i_title_2);
		//getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);  
		Intent i=this.getIntent();
		Bundle bd=i.getExtras();
		profileid=bd.getInt("Profile_id");
		father=bd.getInt("father");
		call=bd.getInt("call");
		
		listAccount = (ExpandableListView) findViewById(R.id.listAccount);
		
        leftBtn = (Button) findViewById(R.id.title_left_btn);
        rightBtn0 = (Button) findViewById(R.id.title_right_btn0);
        rightBtn = (Button) findViewById(R.id.title_right_btn);
        rightBtn2 = (Button) findViewById(R.id.title_right_btn2);
        leftBtn.setText("后退");
        rightBtn.setText("保存");
		rightBtn2.setText("上传");
        rightBtn0.setText("删除");
        leftBtn.setOnClickListener(this);
        rightBtn.setOnClickListener(this);
        rightBtn2.setOnClickListener(this);
        rightBtn0.setOnClickListener(this);
        
        mRoot = (ScrollPeopleLayout) findViewById(R.id.root);
        
        phfv=new PerHealthFirstView(this,profileid);
		pi1=new person_info(this,profileid);
		pi2=new person_info2(this,profileid);
		ht_1 = new HealthTest_1(this,profileid,1);
		ht_2 = new HealthTest_2(this,profileid,1);
		ht_3 = new HealthTest_3(this,profileid,1);
		ht_4 = new HealthTest_4(this,profileid,1);
		ht_5 = new HealthTest_5(this,profileid,1);
		ht_6 = new HealthTest_6(this,profileid,1);
		jzv=new JiezhenView(this,profileid,1);
		hzv=new HuizhenView(this,profileid,1);
		phfv.setTag(FIRST_INTENT_TAG);
		pi1.setTag(SECOND_INTENT_TAG);
		pi2.setTag(THIRD_INTENT_TAG);
		ht_1.setTag(FOUR_INTENT_TAG);
		ht_2.setTag(FIVE_INTENT_TAG);
		ht_3 .setTag(SIX_INTENT_TAG);
		ht_4 .setTag(SEVEN_INTENT_TAG);
		ht_5 .setTag(EIGHT_INTENT_TAG);
		ht_6 .setTag(NINE_INTENT_TAG);
		jzv.setTag(TEN_INTENT_TAG);
		hzv.setTag(ELEVEN_INTENT_TAG);
		mRoot.addView(phfv);
		mRoot.addView(pi1);
		mRoot.addView(pi2);
		mRoot.addView(ht_1);
		mRoot.addView(ht_2);
		mRoot.addView(ht_3);
		mRoot.addView(ht_4);
		mRoot.addView(ht_5);
		mRoot.addView(ht_6);
		mRoot.addView(jzv);
		mRoot.addView(hzv);
		mRoot.setToScreen(0);
        pageIndex=0;
        mpDialog = new ProgressDialog(PeopleScrollActivity.this);  
 		mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
 		mpDialog.setMessage("正在加载...");  
 		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
 		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
 		mpDialog.show();
 		new myThread(handler,"",2).start();	  
 		
 		listAccount.setOnGroupClickListener(new OnGroupClickListener(){

			@Override
			public boolean onGroupClick(ExpandableListView parent, View v,
					int groupPosition, long id) {
				// TODO Auto-generated method stub
				switch(groupPosition){
				case 0:{
					mRoot.setToScreen(0);
					rightBtn0.setVisibility(View.INVISIBLE);
					return true;
				}
				case 1:{
					mRoot.setToScreen(1);
	        		rightBtn0.setText("修改");
	        		rightBtn0.setVisibility(View.VISIBLE);
	        		return true;
				}
				case 2:{
					mRoot.setToScreen(3);
	        		rightBtn0.setText("新建");
	        		rightBtn0.setVisibility(View.VISIBLE);
	        		return false;
				}
				case 3:{
					mRoot.setToScreen(9);
	        		rightBtn0.setText("新建");
	        		rightBtn0.setVisibility(View.VISIBLE);
	        		return false;
				}
				case 4:{
					mRoot.setToScreen(10);
	        		rightBtn0.setText("新建");
	        		rightBtn0.setVisibility(View.VISIBLE);
	        		return false;
				}
				default:
					return false;
				}
			}
 			
 		});
 		
 		listAccount.setOnChildClickListener(new OnChildClickListener(){

			@Override
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				// TODO Auto-generated method stub
				
        		rightBtn0.setText("新建");
        		rightBtn0.setVisibility(View.VISIBLE);
        		
				if(groupPosition==2){
					mRoot.setToScreen(3);
					Toast.makeText(PeopleScrollActivity.this,"第 "+(childPosition+1)+" 次健康体检表",Toast.LENGTH_LONG).show();
					ht_1.setProfileid(profileid);
					ht_1.setTestid((childPosition+1));
					ht_1.fetchData();
					ht_1.initViews();
					ht_2.setProfileid(profileid);
					ht_2.setTestid((childPosition+1));
					ht_2.fetchData();
					ht_2.initViews();
					ht_3.setProfileid(profileid);
					ht_3.setTestid((childPosition+1));
					ht_3.fetchData();
					ht_3.initViews();
					ht_4.setProfileid(profileid);
					ht_4.setTestid((childPosition+1));
					ht_4.fetchData();
					ht_4.initViews();
					ht_5.setProfileid(profileid);
					ht_5.setTestid((childPosition+1));
					ht_5.fetchData();
					ht_5.initViews();
					ht_6.setProfileid(profileid);
					ht_6.setTestid((childPosition+1));
					ht_6.fetchData();
					ht_6.initViews();
					
				}
				else if(groupPosition==3){
					mRoot.setToScreen(9);
					Toast.makeText(PeopleScrollActivity.this,"第 "+(childPosition+1)+" 次接诊记录表",Toast.LENGTH_LONG).show();
					jzv = new JiezhenView(PeopleScrollActivity.this,profileid,(childPosition+1));
					jzv.initWeidget();
					jzv.initView();
				}
				else if(groupPosition==4){
					mRoot.setToScreen(10);
					Toast.makeText(PeopleScrollActivity.this,"第 "+(childPosition+1)+" 次会诊记录表",Toast.LENGTH_LONG).show();
					hzv = new HuizhenView(PeopleScrollActivity.this,profileid,(childPosition+1));
					hzv.initWeidget();
					hzv.initView();
				}
				return false;
			}
 			
 		});
		
		gvModule=(GridView)this.findViewById(R.id.gride2);
		initModuleList();
		gvModule.setOnItemClickListener(new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				// TODO Auto-generated method stub
				Map<String, Object> item = items.get(position);
				int itemID = Integer.parseInt(item.get("itemid").toString());
				Log.i(TAG, "selected module id="+itemID);
				switch(itemID){
				case MODULE_HEALTH_EDU:{//健康教育
					if(father==MODULE_FATHER){
						Intent editprofile = new Intent();
						Bundle bd = new Bundle();
						bd.putInt("Profile_id", profileid);//待编辑档案的ID
						bd.putInt("father", MODULE_CHILD);
						bd.putInt("call", MODULE_PEOPLE_HEALTH);
						editprofile.putExtras(bd);
						editprofile.setClass(PeopleScrollActivity.this, HealthMain.class);
						startActivity(editprofile);
						overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
					}
					else if(father==MODULE_CHILD){
						if(call==MODULE_CHILD_MANAGEMENT){
							finish();
							overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
						}
						else{
							Intent editprofile = new Intent();
							Bundle bd = new Bundle();
							bd.putInt("Profile_id", profileid);//待编辑档案的ID
							bd.putInt("father", MODULE_CHILD);
							bd.putInt("call", call);
							editprofile.putExtras(bd);
							editprofile.setClass(PeopleScrollActivity.this, HealthMain.class);
							startActivity(editprofile);
							overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
							finish();
						}
					}
					break;
				}
				case MODULE_EPIDEMIC:{//疫情上报
					if(father==MODULE_FATHER){
						Intent editprofile = new Intent();
						Bundle bd = new Bundle();
						bd.putInt("Profile_id", profileid);//待编辑档案的ID
						bd.putInt("father", MODULE_CHILD);
						bd.putInt("call", MODULE_PEOPLE_HEALTH);
						editprofile.putExtras(bd);
						editprofile.setClass(PeopleScrollActivity.this, EpidemicList.class);
						startActivity(editprofile);
						overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
					}
					else if(father==MODULE_CHILD){
						if(call==MODULE_CHILD_MANAGEMENT){
							finish();
							overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
						}
						else{
							Intent editprofile = new Intent();
							Bundle bd = new Bundle();
							bd.putInt("Profile_id", profileid);//待编辑档案的ID
							bd.putInt("father", MODULE_CHILD);
							bd.putInt("call", call);
							editprofile.putExtras(bd);
							editprofile.setClass(PeopleScrollActivity.this, EpidemicList.class);
							startActivity(editprofile);
							overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
							finish();
						}
					}
					break;
				}
				case MODULE_VACCINATION:{//预防接种
					if(ifVaccineUsing()){
						if(father==MODULE_FATHER){
							Intent editprofile = new Intent();
							Bundle bd = new Bundle();
							bd.putInt("Profile_id", profileid);//待编辑档案的ID
							bd.putInt("father", MODULE_CHILD);
							bd.putInt("call", MODULE_PEOPLE_HEALTH);
							editprofile.putExtras(bd);
							editprofile.setClass(PeopleScrollActivity.this, VaccinationScrollActivity.class);
							startActivity(editprofile);
							overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
						}
						else if(father==MODULE_CHILD){
							if(call==MODULE_WOMEN_MANAGEMENT){
								finish();
								overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
							}
							else{
								Intent editprofile = new Intent();
								Bundle bd = new Bundle();
								bd.putInt("Profile_id", profileid);//待编辑档案的ID
								bd.putInt("father", MODULE_CHILD);
								bd.putInt("call", call);
								editprofile.putExtras(bd);
								editprofile.setClass(PeopleScrollActivity.this, VaccinationScrollActivity.class);
								startActivity(editprofile);
								overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
								finish();
							}
						}
					}
					else {
						new AlertDialog.Builder(PeopleScrollActivity.this)
		                .setIcon(R.drawable.alert_dialog_icon)
		                .setTitle("您是否要开启该用户的预防接种管理模块？")
		                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                       	mpDialog = new ProgressDialog(PeopleScrollActivity.this);  
		                 		mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
		                 		mpDialog.setMessage("正在开启...");  
		                 		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
		                 		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
		                 		mpDialog.show();
		                 		new myThread(handler,"",8).start();	 
		                    }
		                })
		                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                        /* User clicked Cancel so do some stuff */
		                    }
		                })
		                .create().show();
						
					}
					break;
				}
				case MODULE_ENTERTANCE:{//寓教于乐
					if(father==MODULE_FATHER){
						Intent editprofile = new Intent();
						Bundle bd = new Bundle();
						bd.putInt("Profile_id", profileid);//待编辑档案的ID
						bd.putInt("father", MODULE_CHILD);
						bd.putInt("call", MODULE_PEOPLE_HEALTH);
						editprofile.putExtras(bd);
						editprofile.setClass(PeopleScrollActivity.this, YuleActivity.class);
						startActivity(editprofile);
						overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
					}
					else if(father==MODULE_CHILD){
						if(call==MODULE_CHILD_MANAGEMENT){
							finish();
							overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
						}
						else{
							Intent editprofile = new Intent();
							Bundle bd = new Bundle();
							bd.putInt("Profile_id", profileid);//待编辑档案的ID
							bd.putInt("father", MODULE_CHILD);
							bd.putInt("call", call);
							editprofile.putExtras(bd);
							editprofile.setClass(PeopleScrollActivity.this, YuleActivity.class);
							startActivity(editprofile);
							overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
							finish();
						}
					}
					break;
				}
				case MODULE_SUPERVISE:{//卫生监督
					
					break;
				}
				case MODULE_CHILD_MANAGEMENT:{//儿童管理
					if(ifChildUsing()){
						if(father==MODULE_FATHER){
							Intent editprofile = new Intent();
							Bundle bd = new Bundle();
							bd.putInt("Profile_id", profileid);//待编辑档案的ID
							bd.putInt("father", MODULE_CHILD);
							bd.putInt("call", MODULE_PEOPLE_HEALTH);
							editprofile.putExtras(bd);
							editprofile.setClass(PeopleScrollActivity.this, ChildScrollActivity.class);
							startActivity(editprofile);
							overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
						}
						else if(father==MODULE_CHILD){
							if(call==MODULE_CHILD_MANAGEMENT){
								finish();
								overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
							}
							else{
								Intent editprofile = new Intent();
								Bundle bd = new Bundle();
								bd.putInt("Profile_id", profileid);//待编辑档案的ID
								bd.putInt("father", MODULE_CHILD);
								bd.putInt("call", call);
								editprofile.putExtras(bd);
								editprofile.setClass(PeopleScrollActivity.this, ChildScrollActivity.class);
								startActivity(editprofile);
								overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
								finish();
							}
						}
					}
					else {
						new AlertDialog.Builder(PeopleScrollActivity.this)
		                .setIcon(R.drawable.alert_dialog_icon)
		                .setTitle("您是否要开启该用户的0~6岁儿童管理模块？")
		                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                        /* User clicked OK so do some stuff */
		                    	mpDialog = new ProgressDialog(PeopleScrollActivity.this);  
		                 		mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
		                 		mpDialog.setMessage("正在开启...");  
		                 		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
		                 		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
		                 		mpDialog.show();
		                 		new myThread(handler,"",1).start();	                   
		                    }
		                })
		                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                        /* User clicked Cancel so do some stuff */
		                    }
		                })
		                .create().show();
						
						
					}
					break;
				}
				case MODULE_WOMEN_MANAGEMENT:{//孕产妇管理
					if(ifWomenUsing()){
						if(father==MODULE_FATHER){
							Intent editprofile = new Intent();
							Bundle bd = new Bundle();
							bd.putInt("Profile_id", profileid);//待编辑档案的ID
							bd.putInt("father", MODULE_CHILD);
							bd.putInt("call", MODULE_PEOPLE_HEALTH);
							editprofile.putExtras(bd);
							editprofile.setClass(PeopleScrollActivity.this, PregnantScrollActivity.class);
							startActivity(editprofile);
							overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
						}
						else if(father==MODULE_CHILD){
							if(call==MODULE_WOMEN_MANAGEMENT){
								finish();
								overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
							}
							else{
								Intent editprofile = new Intent();
								Bundle bd = new Bundle();
								bd.putInt("Profile_id", profileid);//待编辑档案的ID
								bd.putInt("father", MODULE_CHILD);
								bd.putInt("call", call);
								editprofile.putExtras(bd);
								editprofile.setClass(PeopleScrollActivity.this, PregnantScrollActivity.class);
								startActivity(editprofile);
								overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
								finish();
							}
						}
					}
					else {
						new AlertDialog.Builder(PeopleScrollActivity.this)
		                .setIcon(R.drawable.alert_dialog_icon)
		                .setTitle("您是否要开启该用户的孕妇管理模块？")
		                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                       		                    	mpDialog = new ProgressDialog(PeopleScrollActivity.this);  
		                 		mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
		                 		mpDialog.setMessage("正在开启...");  
		                 		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
		                 		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
		                 		mpDialog.show();
		                 		new myThread(handler,"",3).start();	 
		                    }
		                })
		                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                        /* User clicked Cancel so do some stuff */
		                    }
		                })
		                .create().show();
						
						
					}
					break;
				}
				case MODULE_ODLS_MANAGEMENT:{//老年人管理
					
					break;
				}
				case MODULE_HT_MANAGEMENT:{//高血压患者管理
					
					break;
				}
				case MODULE_DIABET_MANAGEMENT:{//糖尿病患者管理
					if(ifDiabetUsing()){
						if(father==MODULE_FATHER){
							Intent editprofile = new Intent();
							Bundle bd = new Bundle();
							bd.putInt("Profile_id", profileid);//待编辑档案的ID
							bd.putInt("father", MODULE_CHILD);
							bd.putInt("call", MODULE_PEOPLE_HEALTH);
							editprofile.putExtras(bd);
							editprofile.setClass(PeopleScrollActivity.this, DiabeterDetails.class);
							startActivity(editprofile);
							overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
						}
						else if(father==MODULE_CHILD){
							if(call==MODULE_WOMEN_MANAGEMENT){
								finish();
								overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
							}
							else{
								Intent editprofile = new Intent();
								Bundle bd = new Bundle();
								bd.putInt("Profile_id", profileid);//待编辑档案的ID
								bd.putInt("father", MODULE_CHILD);
								bd.putInt("call", call);
								editprofile.putExtras(bd);
								editprofile.setClass(PeopleScrollActivity.this, DiabeterDetails.class);
								startActivity(editprofile);
								overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
								finish();
							}
						}
					}
					else {
						new AlertDialog.Builder(PeopleScrollActivity.this)
		                .setIcon(R.drawable.alert_dialog_icon)
		                .setTitle("您是否要开启该用户的2型糖尿病管理模块？")
		                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                       	mpDialog = new ProgressDialog(PeopleScrollActivity.this);  
		                 		mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
		                 		mpDialog.setMessage("正在开启...");  
		                 		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
		                 		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
		                 		mpDialog.show();
		                 		new myThread(handler,"",9).start();	 
		                    }
		                })
		                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                        /* User clicked Cancel so do some stuff */
		                    }
		                })
		                .create().show();
						
					}
					break;
				}
				case MODULE_MENTAL_MANAGEMENT:{//精神疾病患者管理
					if(ifMentalUsing()){
						if(father==MODULE_FATHER){
							Intent editprofile = new Intent();
							Bundle bd = new Bundle();
							bd.putInt("Profile_id", profileid);//待编辑档案的ID
							bd.putInt("father", MODULE_CHILD);
							bd.putInt("call", MODULE_PEOPLE_HEALTH);
							editprofile.putExtras(bd);
							editprofile.setClass(PeopleScrollActivity.this, MentalerDetails.class);
							startActivity(editprofile);
							overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
						}
						else if(father==MODULE_CHILD){
							if(call==MODULE_WOMEN_MANAGEMENT){
								finish();
								overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
							}
							else{
								Intent editprofile = new Intent();
								Bundle bd = new Bundle();
								bd.putInt("Profile_id", profileid);//待编辑档案的ID
								bd.putInt("father", MODULE_CHILD);
								bd.putInt("call", call);
								editprofile.putExtras(bd);
								editprofile.setClass(PeopleScrollActivity.this, MentalerDetails.class);
								startActivity(editprofile);
								overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
								finish();
							}
						}
					}
					else {
						new AlertDialog.Builder(PeopleScrollActivity.this)
		                .setIcon(R.drawable.alert_dialog_icon)
		                .setTitle("您是否要开启该用户的重性精神疾病管理模块？")
		                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                       	mpDialog = new ProgressDialog(PeopleScrollActivity.this);  
		                 		mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
		                 		mpDialog.setMessage("正在开启...");  
		                 		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
		                 		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
		                 		mpDialog.show();
		                 		new myThread(handler,"",7).start();	 
		                    }
		                })
		                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                        /* User clicked Cancel so do some stuff */
		                    }
		                })
		                .create().show();
						
					}
					break;
				}
				
				}
			}
			
		});
		
		initExList();
    }
    
    /**
     * 初始化模块导航条
     */
    private void initModuleList() {
		// TODO Auto-generated method stub
    	items = new ArrayList<Map<String,Object>>();
		for(int k=0;k<nameOfInitialModuels.length;k++){
			HashMap<String, Object> item = new HashMap<String, Object>();
			item.put("image", imageOfInitialModuels[k]);
			item.put("name", nameOfInitialModuels[k]);
			item.put("itemid", idOfInitialModuels[k]);
			items.add(item);
		}
		if(pi1.getAge()>=0&&pi1.getAge()<=6){//显示儿童模块导航
			HashMap<String, Object> item = new HashMap<String, Object>();
			item.put("image", R.drawable.childguanli);
			item.put("name", "0-6岁儿童健康档案管理");
			item.put("itemid", MODULE_CHILD_MANAGEMENT);
			items.add(item);
		}
		else if(pi1.getAge()>=60){//显示老年人模块导航
			
		}
		if(pi1.getGender()==2&&pi1.getMarriage()==2){//已婚女性可显示孕产妇模块导航
			HashMap<String, Object> item = new HashMap<String, Object>();
			item.put("image", R.drawable.yunfuguanli);
			item.put("name", "孕产妇童健康档案管理");
			item.put("itemid", MODULE_WOMEN_MANAGEMENT);
			items.add(item);
		}
		if(pi1.getHT()){//显示高血压导航
			
		}
		if(pi1.getDiabet()){//显示糖尿病导航
			HashMap<String, Object> item = new HashMap<String, Object>();
			item.put("image", R.drawable.diabet);
			item.put("name", "糖尿病患者健康管理");
			item.put("itemid", MODULE_DIABET_MANAGEMENT);
			items.add(item);
		}
		if(pi1.getMentalIll()){//显示精神病导航
			HashMap<String, Object> item = new HashMap<String, Object>();
			item.put("image", R.drawable.mental_ill);
			item.put("name", "重性精神疾病患者管理");
			item.put("itemid", MODULE_MENTAL_MANAGEMENT);
			items.add(item);
		}
		SimpleAdapter adapter = new SimpleAdapter(
				this,
				items,
				R.layout.module_item_view,
				new String[]{"image","name",},
				new int[]{R.id.module_image,R.id.module_name});
		gvModule.setAdapter(adapter);
	}

	@Override
    protected void onRestart() {
    	super.onRestart();

    	Log.d(TAG, "onRestart");

    }
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v==leftBtn){//退出
			new AlertDialog.Builder(PeopleScrollActivity.this)
			.setIcon(R.drawable.alert_dialog_icon)
			.setTitle("您确定已经保存了要退出吗？")
			.setPositiveButton("确定", new DialogInterface.OnClickListener(){
				public void onClick(DialogInterface dialog, int whichButton) {
//					startActivity(new Intent(PeopleScrollActivity.this, PeopleList.class));
					finish();
					overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
				}
			})
			.setNegativeButton("取消", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {

		                        /* User clicked Cancel so do some stuff */
		                   }
		                })
		                .create().show();
		}
		else if(v==rightBtn2){//提交
			pageIndex=mRoot.getCurScreen();
			switch(pageIndex){
			case 0:
			case 1:
			case 2:{//个人基本信息
				boolean check = pi1.checkIntegrity();
				if(check){
					new AlertDialog.Builder(PeopleScrollActivity.this)
					.setTitle("提交")
					.setMessage("请再次核对信息，确保信息的准确性和完整性。提交后信息将不能随意更改！")
					.setPositiveButton("提交", new DialogInterface.OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							// TODO Auto-generated method stub
							
							uploadPersonInfo();
						}
					})
					.setNegativeButton("核对信息", new DialogInterface.OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							// TODO Auto-generated method stub
							
						}
					}).create().show();
				}
				break;
			}
			}
			
		}
		else if(v==rightBtn){//保存
//			System.out.println("pageIndex="+pageIndex);
			pageIndex=mRoot.getCurScreen();
			int i=0;
			switch(pageIndex){
			case 0:
				phfv.saveView();
				i=0;
				break;
			case 1:
				pi1.saveView();
				pi2.saveView();
				
				pi1.selectData();
				initModuleList();
				i=1;
			//	pi1.modifyPersonInfo1();
				break;
			case 2:
				pi1.saveView();
				pi2.saveView();
				i=1;
			//	pi2.modifyPersonInfo2();
				break;
			case 3:
				ht_1.saveViews();
				ht_2.saveViews();
				ht_3.saveViews();
				ht_4.saveViews();
				ht_5.saveViews();
				ht_6.saveViews();
				i=2;
				break;
			case 4:
				ht_1.saveViews();
				ht_2.saveViews();
				ht_3.saveViews();
				ht_4.saveViews();
				ht_5.saveViews();
				ht_6.saveViews();
				i=2;
				break;
			case 5:
				ht_1.saveViews();
				ht_2.saveViews();
				ht_3.saveViews();
				ht_4.saveViews();
				ht_5.saveViews();
				ht_6.saveViews();
				i=2;
				break;
			case 6:
				ht_1.saveViews();
				ht_2.saveViews();
				ht_3.saveViews();
				ht_4.saveViews();
				ht_5.saveViews();
				ht_6.saveViews();
				i=2;
				break;
			case 7:
				ht_1.saveViews();
				ht_2.saveViews();
				ht_3.saveViews();
				ht_4.saveViews();
				ht_5.saveViews();
				ht_6.saveViews();
				i=2;
				break;
			case 8:
				ht_1.saveViews();
				ht_2.saveViews();
				ht_3.saveViews();
				ht_4.saveViews();
				ht_5.saveViews();
				ht_6.saveViews();
				i=2;
				break;
			case 9:
				jzv.saveView();
				i=3;
				break;
			case 10:
				
				hzv.saveView();
				i=4;
				break;
			}
			Toast.makeText(this, table[i]+"表保存成功!", Toast.LENGTH_SHORT).show();
			
		}
		else if(v==rightBtn0){//新建、修改、删除
			pageIndex = mRoot.getCurScreen();
			System.out.println("pageIndex="+pageIndex);
			switch(pageIndex){
			case 0:
				new AlertDialog.Builder(this)
				.setIcon(android.R.drawable.ic_dialog_alert)
				.setTitle("删除提醒")
				.setMessage("档案删除后将不可恢复，请您慎重操作。确定要删除这份档案吗？")
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						mpDialog = new ProgressDialog(PeopleScrollActivity.this);  
			     		mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
			     		mpDialog.setMessage("正在删除档案...");  
			     		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
			     		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
			     		mpDialog.show();
			     		new myThread(handler,"",10).start();
					}
				})
				.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						
					}
				})
				.create().show();
				
				break;
			case 1:
			case 2:
				
				break;
			case 3:
			case 4:
			case 5:
			case 6:
			case 7:
			case 8:
				new AlertDialog.Builder(PeopleScrollActivity.this)
				.setTitle("新建体检表")
				.setIcon(R.drawable.add_profile)
				.setMessage("您确定要保存当前体检表的信息，并且建立一张新的体检表吗？")
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
                 		mpDialog.setMessage("正在保存当前信息...");  
                 		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
                 		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
                 		mpDialog.show();
                 		//保存当前体检表的信息
        				ht_1.saveViews();
        				ht_2.saveViews();
        				ht_3.saveViews();
        				ht_4.saveViews();
        				ht_5.saveViews();
        				ht_6.saveViews();
        			    //新建
                 		new createNewTestThread(handler).start();	 
					}
				})
				.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						
					}
				})
				.create().show();
				break;
			case 9:
				LayoutInflater factory = LayoutInflater.from(PeopleScrollActivity.this);
	            final View textEntryView = factory.inflate(R.layout.jiezhen_layout, null);
	            EditText et_name=(EditText)textEntryView.findViewById(R.id.et_jiezhen_name);
            	EditText et_id=(EditText)textEntryView.findViewById(R.id.et_jiezhen_id);
            	et_name.setInputType(InputType.TYPE_NULL);
            	et_id.setInputType(InputType.TYPE_NULL);
            	et_name.setText(ht.getHeti_name());
            	et_id.setText(ht.getHeti_here_id());
            	final EditText et_zhuguan=(EditText)textEntryView.findViewById(R.id.et_jiezhen_zhuguan);
            	final EditText et_keguan=(EditText)textEntryView.findViewById(R.id.et_jiezhen_keguan);
            	final EditText et_pinggu=(EditText)textEntryView.findViewById(R.id.et_jiezhen_pinggu);
            	final EditText et_plan=(EditText)textEntryView.findViewById(R.id.et_jiezhen_plan);
            	final EditText et_doctor=(EditText)textEntryView.findViewById(R.id.et_jiezhen_doctor);
            	final EditText et_date=(EditText)textEntryView.findViewById(R.id.et_jiezhen_date);
            	et_date.setInputType(InputType.TYPE_NULL);
            	et_date.setOnClickListener(new OnClickListener(){

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						mPopupWindow = new MyPopupWindow(PeopleScrollActivity.this);			
						mPopupWindow.showAtLocation(textEntryView.findViewById(R.id.et_jiezhen_date), Gravity.CENTER, 0, 0);

						Button btn=mPopupWindow.getButton();
						btn.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View v) {
								// TODO Auto-generated method stub
								et_date.setText(mPopupWindow.getDate());
								mPopupWindow.dismiss();
							}
							
						});
					}
            		
            	});
	            ad=new AlertDialog.Builder(PeopleScrollActivity.this)
	                .setIcon(R.drawable.add_profile)
	                .setTitle("新建接诊表")
	                .setView(textEntryView)
	                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked Yes so do some stuff */
                    	
                    	jzr=new JieZhenRecord(PeopleScrollActivity.this);
                    	jzr.setThre_profileid(profileid);
                    	jzr.setThre_obje_info(et_zhuguan.getText().toString());
                		jzr.setThre_subj_info(et_keguan.getText().toString());
                		jzr.setThre_eval(et_pinggu.getText().toString());
                		jzr.setThre_plan(et_plan.getText().toString());
                		jzr.setThre_doct(et_doctor.getText().toString());
                		jzr.setThre_date(et_date.getText().toString());
                		mpDialog = new ProgressDialog(PeopleScrollActivity.this);  
                 		mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
                 		mpDialog.setMessage("正在创建接诊记录...");  
                 		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
                 		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
                 		mpDialog.show();
                 		new myThread(handler,"",4).start();	
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked No so do some stuff */
                    }
                })
               .create();
	            ad.show();
	            
				break;
			case 10:
				LayoutInflater factory1 = LayoutInflater.from(PeopleScrollActivity.this);
	            final View textEntryView1 = factory1.inflate(R.layout.huizhen_layout, null);
	            EditText et_name1=(EditText)textEntryView1.findViewById(R.id.et_huizhen_name);
	            EditText et_id1=(EditText)textEntryView1.findViewById(R.id.et_huizhen_id);
	    		et_name1.setInputType(InputType.TYPE_NULL);
	    		et_id1.setInputType(InputType.TYPE_NULL);
	    		et_name1.setText(ht.getHeti_name());
            	et_id1.setText(ht.getHeti_here_id());
            	final EditText et_reason=(EditText)textEntryView1.findViewById(R.id.et_huizhen_reason);
            	final EditText et_opinion=(EditText)textEntryView1.findViewById(R.id.et_huizhen_opin);
            	final EditText et_inst_1=(EditText)textEntryView1.findViewById(R.id.et_huizhen_inst_1);
            	final EditText et_inst_2=(EditText)textEntryView1.findViewById(R.id.et_huizhen_inst_2);
            	final EditText et_inst_3=(EditText)textEntryView1.findViewById(R.id.et_huizhen_inst_3);
            	final EditText et_inst_4=(EditText)textEntryView1.findViewById(R.id.et_huizhen_inst_4);
            	final EditText et_inst_5=(EditText)textEntryView1.findViewById(R.id.et_huizhen_inst_5);
            	final EditText et_doctor_1=(EditText)textEntryView1.findViewById(R.id.et_huizhen_doctor_1);
            	final EditText et_doctor_2=(EditText)textEntryView1.findViewById(R.id.et_huizhen_doctor_2);
            	final EditText et_doctor_3=(EditText)textEntryView1.findViewById(R.id.et_huizhen_doctor_3);
            	final EditText et_doctor_4=(EditText)textEntryView1.findViewById(R.id.et_huizhen_doctor_4);
            	final EditText et_doctor_5=(EditText)textEntryView1.findViewById(R.id.et_huizhen_doctor_5);
            	final EditText et_doctor1=(EditText)textEntryView1.findViewById(R.id.et_huizhen_doctor);
            	final EditText et_date1=(EditText)textEntryView1.findViewById(R.id.et_huizhen_date);
        		et_date1.setInputType(InputType.TYPE_NULL);
        		et_date1.setOnClickListener(new OnClickListener(){

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						mPopupWindow = new MyPopupWindow(PeopleScrollActivity.this);			
						mPopupWindow.showAtLocation(textEntryView1.findViewById(R.id.et_huizhen_date), Gravity.CENTER, 0, 0);

						Button btn=mPopupWindow.getButton();
						btn.setOnClickListener(new OnClickListener(){

							@Override
							public void onClick(View v) {
								// TODO Auto-generated method stub
								et_date1.setText(mPopupWindow.getDate());
								mPopupWindow.dismiss();
							}
							
						});
					}
        			
        		});
        		 ad=new AlertDialog.Builder(PeopleScrollActivity.this)
	                .setIcon(R.drawable.add_profile)
	                .setTitle("新建会诊表")
	                .setView(textEntryView1)
	                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int whichButton) {

                     /* User clicked Yes so do some stuff */
                 	
                 	hzr=new HuiZhenRecord(PeopleScrollActivity.this);
                 	hzr.setCore_reason(et_reason.getText().toString());
                 	hzr.setCore_opinion(et_opinion.getText().toString());
                 	hzr.setCore_inst_1(et_inst_1.getText().toString());
                 	hzr.setCore_inst_2(et_inst_2.getText().toString());
                 	hzr.setCore_inst_3(et_inst_3.getText().toString());
                 	hzr.setCore_inst_4(et_inst_4.getText().toString());
                 	hzr.setCore_inst_5(et_inst_5.getText().toString());
                 	hzr.setCore_doct_1(et_doctor_1.getText().toString());
                 	hzr.setCore_doct_2(et_doctor_2.getText().toString());
                 	hzr.setCore_doct_3(et_doctor_3.getText().toString());
                 	hzr.setCore_doct_4(et_doctor_4.getText().toString());
                 	hzr.setCore_doct_5(et_doctor_5.getText().toString());
                 	hzr.setCore_doct(et_doctor1.getText().toString());
                 	hzr.setCore_date(et_date1.getText().toString());
             		mpDialog = new ProgressDialog(PeopleScrollActivity.this);  
              		mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
              		mpDialog.setMessage("正在创建会诊记录...");  
              		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
              		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
              		mpDialog.show();
              		new myThread(handler,"",5).start();	
                 }
             })
             .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int whichButton) {

                     /* User clicked No so do some stuff */
                 }
             })
            .create();
	            ad.show();
				break;
			}
		}
	}

	/**
	 * 从数据库中删除健康档案
	 * @param id 健康档案编号
	 */
	private void deleteProfile(int id) {
		// TODO Auto-generated method stub
		HereTipa ht = new HereTipa(this);
		ht.delectHereTipa(id);
		PersonInfo pi = new PersonInfo(this);
		pi.deletePersonInfo(id);
		HealthTest test = new HealthTest(this);
		test.delectHealthTest(id);
		HospitalHistory hh = new HospitalHistory(this);
		hh.delectHospitalHistory(id);
		SickbedHistory sh = new SickbedHistory(this);
		sh.delectSickbedHistory(id);
		MedicateRecord mr = new MedicateRecord(this);
		mr.delectMedicateRecord(id);
		NonimmuneVaccineHistory nh = new NonimmuneVaccineHistory(this);
		nh.delectNonimmuneVaccineHistory(id);
		JieZhenRecord jz = new JieZhenRecord(this);
		jz.deleteJieZhenRecord(id);
		HuiZhenRecord hz = new HuiZhenRecord(this);
		hz.deleteHuiZhenRecord(id);
		
		ModuleSelect ms = new ModuleSelect(this);
		ms.deleteModuleSelect(id);
		EpidemicRecord er = new EpidemicRecord(this);
		er.delectEpidemicRecord(id);
		VaccinationCard vc = new VaccinationCard(this);
		vc.deleteVaccinationCard(id);
		VaccinationRecord vr = new VaccinationRecord(this);
		vr.deleteVaccinationRecord(id);
		NewBornChild nc = new NewBornChild(this);
		nc.deleteNewBornChild(id);
		OneChild oc = new OneChild(this);
		oc.deleteOneChild(id);
		TwoChild tc = new TwoChild(this);
		tc.deleteTwoChild(id);
		ThreeChild thc = new ThreeChild(this);
		thc.deleteThreeChild(id);
		FirstPrenatalVisit fpv = new FirstPrenatalVisit(this);
		fpv.delectFirstPrenatalVisit(id);
		PrenatalVisit pv = new PrenatalVisit(this);
		pv.delectPrenatalVisit(id);
		PostnatalVisit pov = new PostnatalVisit(this);
		pov.delectPostnatalVisit(id);
		LastPostnatalCheck lpc = new LastPostnatalCheck(this);
		lpc.delectLastPostnatalCheck(id);
		DiabetService ds = new DiabetService(this);
		ds.deleteDiabetService(id);
		MentalerInfo mi = new MentalerInfo(this);
		mi.deleteMentalerInfo(id);
		VisitMentals vm = new VisitMentals(this);
		vm.deleteVisitMentals(id);
		
	}

	/**
	 * 提交个人基本信息
	 */
	protected void uploadPersonInfo() {
		// TODO Auto-generated method stub
		pi1.saveView();
		pi2.saveView();
		pi1.disableViews();
		pi2.disableViews();
		mpDialog = new ProgressDialog(PeopleScrollActivity.this);  
 		mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//设置风格为圆形进度条  
 		mpDialog.setMessage("正在提交，请稍等...");  
 		mpDialog.setIndeterminate(false);//设置进度条是否为不明确  
 		mpDialog.setCancelable(true);//设置进度条是否可以按退回键取消  
 		mpDialog.show();
 		new UploadThread(handler,1).start();
	}

	private void initExList(){
		accountFather = new ArrayList<String>();
		accountChild = new ArrayList<List<Map<String, String>>>();
		accountFather.add("居民健康档案封面");
		accountFather.add("个人基本信息表");
		accountFather.add("健康体检表");
		accountFather.add("接诊记录表");
		accountFather.add("会诊记录表");
		// 准备第一个一级列表中的二级列表数据:两个二级列表,分别显示"childData1"和"childData2"
		List<Map<String, String>> financeAccount = new ArrayList<Map<String, String>>();
		Map<String, String> child1Data1 = new HashMap<String, String>();
		HereTipa ht=new HereTipa(this);
		ht.selectHereTipa(profileid);
		child1Data1.put(FATHERACCOUNT, "居民健康档案封面");
		child1Data1.put(CHILDACCOUNT, "日期:"+ht.getHeti_buil_date());
		
		financeAccount.add(child1Data1);

		// 准备第二个一级列表中的二级列表数据:一个二级列表,显示"child2Data1"
		List<Map<String, String>> dummyAccount = new ArrayList<Map<String, String>>();
		Map<String, String> child2Data1 = new HashMap<String, String>();
		child2Data1.put(FATHERACCOUNT, "个人基本信息表");
		child2Data1.put(CHILDACCOUNT, "日期:"+ht.getHeti_buil_date());
		
		dummyAccount.add(child2Data1);
		

		// 准备第三个一级列表中的二级列表数据:一个二级列表,显示"child2Data1"
		List<Map<String, String>> cashAccount;
		cashAccount= new ArrayList<Map<String, String>>();
		Map<String, String> child3Data1;
		
		Cursor cursor=this.managedQuery(CONTENT_URI_TB5, PROJECTION, 
				HETE_COLUMN1 + "=" + profileid, null, null);
		int i=1;
		while(cursor.moveToNext()){
			
			child3Data1 = new HashMap<String, String>();
			child3Data1.put(FATHERACCOUNT, "第"+i+"次健康体检表");
			child3Data1.put(CHILDACCOUNT, "日期:"+cursor.getString(0));
		
			cashAccount.add(child3Data1);
//			healthtest_num++;
			i++;
		}
		
		cashAccount1= new ArrayList<Map<String, String>>();
		Map<String, String> child3Data11;
		
		cursor=this.managedQuery(CONTENT_URI_TB10, PROJECTION1, 
				THRE_PROFILEID + "=" + profileid, null, null);
		i=1;
		while(cursor.moveToNext()){
			child3Data11= new HashMap<String, String>();
			child3Data11.put(FATHERACCOUNT, "第"+i+"次接诊记录表");
			child3Data11.put(CHILDACCOUNT,"日期:"+cursor.getString(0));
		
			cashAccount1.add(child3Data11);
			jiezhen_num++;
			i++;
		}
		
		cashAccount2 = new ArrayList<Map<String, String>>();
		
		Map<String, String> child3Data12;
		cursor=this.managedQuery(CONTENT_URI_TB11, PROJECTION2, 
				CORE_PROFILEID + "=" + profileid, null, null);
		i=1;
		while(cursor.moveToNext()){
			child3Data12= new HashMap<String, String>();
			child3Data12.put(FATHERACCOUNT, "第"+i+"次会诊记录表");
			child3Data12.put(CHILDACCOUNT, "日期:"+cursor.getString(0));
		
			cashAccount2.add(child3Data12);
			huizhen_num++;
			i++;
		}
		
		accountChild.add(financeAccount);
		accountChild.add(dummyAccount);
		accountChild.add(cashAccount);
		accountChild.add(cashAccount1);
		accountChild.add(cashAccount2);
		adapter = new AccountExpandablebaseadapter(PeopleScrollActivity.this,
				accountFather, accountChild);
		listAccount.setAdapter(adapter);
		// 去掉系统自带的按钮
		listAccount.setGroupIndicator(null);
		// 去掉系统自带的分隔线
		listAccount.setDivider(null);
	}
	
	private boolean ifChildUsing(){
		ModuleSelect ms=new ModuleSelect(this);
		ms.selectModuleSelect(profileid);
		int i=ms.getMose_0_6_child_health_id();
		if(i>0){
			return true;
		}
		return false;
	}
	
	private boolean ifWomenUsing(){
		ModuleSelect ms=new ModuleSelect(this);
		ms.selectModuleSelect(profileid);
		int i=ms.getMose_maternal_health_id();
		if(i>0){
			return true;
		}
		return false;
	}
	
	private boolean ifMentalUsing(){
		ModuleSelect ms=new ModuleSelect(this);
		ms.selectModuleSelect(profileid);
		int i=ms.getMose_mental_id();
		if(i>0){
			return true;
		}
		return false;
	}
	
	private boolean ifDiabetUsing(){
		ModuleSelect ms=new ModuleSelect(this);
		ms.selectModuleSelect(profileid);
		int i=ms.getMose_diabet2_id();
		if(i>0){
			return true;
		}
		return false;
	}
	
	private boolean  ifVaccineUsing(){
		ModuleSelect ms=new ModuleSelect(this);
		ms.selectModuleSelect(profileid);
		int i=ms.getMose_vaccinate_id();
		if(i>0){
			return true;
		}
		return false;
	}
	public class createNewTestThread extends Thread{
		private Handler handler;
		public createNewTestThread(Handler handler){
			this.handler = handler;
		}
		
		public void run(){
			try{
				Looper.getMainLooper();
				sleep(500);
				
				HealthTest htt=new HealthTest(PeopleScrollActivity.this);
				htt.setHete_profileid(profileid);
				healthtest_num = htt.getHealthTestTimes(profileid)+1;
				System.out.println("healthtest_num="+healthtest_num);
				htt.setHete_testid(healthtest_num);
				htt.insertHealthTest();
				
				//住院史---限填2项
				HospitalHistory hh = new HospitalHistory(PeopleScrollActivity.this);
				hh.setHohi_profileid(profileid);
				hh.setHohi_testid(healthtest_num);
				hh.setHohi_id(1);
				hh.insertHospitalHistory();
				hh.setHohi_profileid(profileid);
				hh.setHohi_testid(healthtest_num);
				hh.setHohi_id(2);
				hh.insertHospitalHistory();
				//病床史---限填2项
				SickbedHistory sh = new SickbedHistory(PeopleScrollActivity.this);
				sh.setSihi_profileid(profileid);
				sh.setSihi_testid(healthtest_num);
				sh.setSihi_id(1);
				sh.insertSickbedHistory();
				sh.setSihi_profileid(profileid);
				sh.setSihi_testid(healthtest_num);
				sh.setSihi_id(2);
				sh.insertSickbedHistory();
				//吃药信息---限填6项
				MedicateRecord mr = new MedicateRecord(PeopleScrollActivity.this);
				mr.setMere_profileid(profileid);
				mr.setMere_testid(healthtest_num);
				mr.setMere_id(1);
				mr.insertMedicateRecord();
				mr.setMere_profileid(profileid);
				mr.setMere_testid(healthtest_num);
				mr.setMere_id(2);
				mr.insertMedicateRecord();
				mr.setMere_profileid(profileid);
				mr.setMere_testid(healthtest_num);
				mr.setMere_id(3);
				mr.insertMedicateRecord();
				mr.setMere_profileid(profileid);
				mr.setMere_testid(healthtest_num);
				mr.setMere_id(4);
				mr.insertMedicateRecord();
				mr.setMere_profileid(profileid);
				mr.setMere_testid(healthtest_num);
				mr.setMere_id(5);
				mr.insertMedicateRecord();
				mr.setMere_profileid(profileid);
				mr.setMere_testid(healthtest_num);
				mr.setMere_id(6);
				mr.insertMedicateRecord();
				//非免疫预防接种---限填3项
				NonimmuneVaccineHistory nvh = new NonimmuneVaccineHistory(PeopleScrollActivity.this);
				nvh.setNovh_profileid(profileid);
				nvh.setNovh_testid(healthtest_num);
				nvh.setNovh_id(1);
				nvh.insertNonimmuneVaccineHistory();
				nvh.setNovh_profileid(profileid);
				nvh.setNovh_testid(healthtest_num);
				nvh.setNovh_id(2);
				nvh.insertNonimmuneVaccineHistory();
				nvh.setNovh_profileid(profileid);
				nvh.setNovh_testid(healthtest_num);
				nvh.setNovh_id(3);
				nvh.insertNonimmuneVaccineHistory();
				
				ht_1.setProfileid(profileid);
				ht_1.setTestid(healthtest_num);
				ht_1.fetchData();
				ht_2.setProfileid(profileid);
				ht_2.setTestid(healthtest_num);
				ht_2.fetchData();
				ht_3.setProfileid(profileid);
				ht_3.setTestid(healthtest_num);
				ht_3.fetchData();
				ht_4.setProfileid(profileid);
				ht_4.setTestid(healthtest_num);
				ht_4.fetchData();
				ht_5.setProfileid(profileid);
				ht_5.setTestid(healthtest_num);
				ht_5.fetchData();
				ht_6.setProfileid(profileid);
				ht_6.setTestid(healthtest_num);
				ht_6.fetchData();
				
				Message msg = handler.obtainMessage();
				msg.what = 6;
				handler.sendMessage(msg);
				
			}
			catch(Exception e){
				e.printStackTrace();
			}
		}
	}
	
	//提交的线程类
	class UploadThread extends Thread{

		private Handler mhandler;
		private int mState;//表示要提交的信息类型
		
		public UploadThread(Handler hl,int state){
			this.mhandler = hl;
			this.mState = state;
			Log.i("upload", "start upload thread");
		}
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			Looper.getMainLooper();
			
			if(mState==1){//个人基本信息
				JSONObject data= new JSONObject();
				try{
					SharedPreferences uinfo = getSharedPreferences(USERINFO, Context.MODE_PRIVATE);
					HereTipa ht0 = new HereTipa(PeopleScrollActivity.this);
					ht0.selectHereTipa(profileid);
					PersonInfo info = pi1.getPersonInfo();
					
					data.put("建档人员姓名", uinfo.getString("operator_name",""));
					data.put("建档人员ID", uinfo.getString("operator_id",""));
					data.put("标示符", uinfo.getString("org_code",""));//"29EE43D6");
					
					data.put("姓名", pi1.getName());
					data.put("建档机构编码", uinfo.getString("org_key",""));
					if(ht0.getHeti_here_id().length()<6){
						data.put("档案编号（区域码）", uinfo.getString("area_code",""));//本地临时档案（编号12位），提交后服务器将创建
					}
					else{
						data.put("档案编号（区域码）", ht0.getHeti_here_id());//（编号18位）提交后服务器更新信息
					}
					
					data.put("性别", ""+info.getPein_sex());
					data.put("出生日期", info.getPein_born());
//					data.put("出生日期", "2011-11-11");//仅当前测试使用
					data.put("身份证号", info.getPein_perid());
					String temp = info.getPein_work();
					if(temp.length()==0){
						data.put("工作单位", "null");
					}else{
						data.put("工作单位", temp);
					}
					temp = info.getPein_phone();
					if(temp.length()==0){
						data.put("本人电话", "null");
					}
					else{
						data.put("本人电话", temp);
					}
					temp = info.getPein_contact_name();
					if(temp.length()==0){
						data.put("联系人姓名", "null");
					}
					else{
						data.put("联系人姓名", temp);
					}
					temp = info.getPein_contact_phone();
					if(temp.length()==0){
						data.put("联系人电话", "null");
					}
					else {
						data.put("联系人电话", temp);
					}
					
					data.put("常住类型", ""+info.getPein_permatent_type());
					
					data.put("民族", info.getNation());
					data.put("血型", ""+info.getPein_blood_type());
					data.put("RH阴性", ""+info.getPein_rh_negative());
					data.put("文化程度", ""+info.getPein_culture_stdd());
					data.put("职业", ""+info.getPein_occupation());
					data.put("婚姻状况", ""+info.getPein_marriage());
					
					data.put("地址", ht0.getHeti_now_addr());
					data.put("组编码", ht0.getAddressGroup());
		    		data.put("籍贯", getResources().getString(R.string.def_area_code));//"640381");
		    		data.put("户籍地组编码", ht0.getHhGroup());
		    		data.put("出生地",getResources().getString(R.string.def_area_code));//"640381");
		    		data.put("户籍地",uinfo.getString("area_code",""));//"640381107206");
					
					data.put("医疗费用支付方式（编码）", info.getPein_hos_cost_type());
					data.put("其他支付方式", info.getPein_hos_cost_type_ot());
					data.put("药物过敏史（编码）", info.getPein_drug_allergy());
					data.put("其他过敏史", info.getPein_drug_allergy_ot());
					data.put("暴露史", info.getPein_exposure_his());
					data.put("既往史（疾病）", info.getPein_disease());
					data.put("既往史（其他疾病）", info.getPein_disease_ot());
					data.put("既往史（疾病时间）", info.getPein_disease_date());
					data.put("既往史（有无手术）", info.getPein_surgery());
					data.put("既往史（手术1）", info.getPein_surgery_name1());
					data.put("既往史（手术1时间）", info.getPein_surgery_date1());
					data.put("既往史（手术2）", info.getPein_surgery_name2());
					data.put("既往史（手术2时间）", info.getPein_surgery_date2());
					data.put("既往史（有无外伤）", info.getPein_trauma());
					data.put("既往史（外伤1）", info.getPein_trauma_name1());
					data.put("既往史（外伤1时间）", info.getPein_trauma_time1());
					data.put("既往史（外伤2）", info.getPein_trauma_name2());
					data.put("既往史（外伤2时间）", info.getPein_trauma_time2());
					data.put("既往史（有无输血）", info.getPein_transfusion());
					data.put("既往史（输血1）", info.getPein_trfusion_reason1());
					data.put("既往史（输血1时间）", info.getPein_trfusion_time1());
					data.put("既往史（输血2）", info.getPein_trfusion_reason2());
					data.put("既往史（输血2时间）", info.getPein_trfusion_time2());
					info = pi2.getPersonInfo();
					data.put("家族史（父亲）", info.getPein_family_his_ft());
					data.put("家族史（父亲其他疾病）", info.getPein_family_his_ft_ot());
					data.put("家族史（母亲）", info.getPein_family_his_mt());
					data.put("家族史（母亲其他疾病）", info.getPein_family_his_mt_ot());
					data.put("家族史（兄妹）", info.getPein_family_his_bs());
					data.put("家族史（兄妹其他疾病）", info.getPein_family_his_bs_ot());
					data.put("家族史（子女）", info.getPein_family_his_sd());
					data.put("家族史（子女其他疾病）", info.getPein_family_his_sd_ot());
					data.put("有无遗传病史", info.getPein_hereditary_his());
					data.put("遗传病名称", info.getPein_hereditary_name());
					data.put("残疾情况（编码）", info.getPein_disable_situ());
					data.put("残疾情况（其他残疾）", info.getPein_disable_situ_ot());
					data.put("生活环境（排风）", ""+info.getPein_live_kit());
					data.put("生活环境（燃料）", ""+info.getPein_live_fuel());
					data.put("生活环境（饮水）", ""+info.getPein_live_water());
					data.put("生活环境（厕所）", ""+info.getPein_live_toilet());
					data.put("生活环境（禽畜栏）", ""+info.getPein_live_stock());
					data.put("责任医生编码", uinfo.getString("doctor_key",""));
					}
				catch(JSONException e){
					e.printStackTrace();
				}
				String sData = data.toString();
				Log.i("upload","person info="+sData);
				
				Message message = mhandler.obtainMessage();
				try {
					String pathUrl = getResources().getString(R.string.url_person_info);
					URL url = new URL(pathUrl);
					HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
					httpConn.setDoOutput(true);
					httpConn.setDoInput(true);
					httpConn.setUseCaches(false);
					httpConn.setRequestMethod("POST");

					byte[] requestStringBytes = sData.getBytes();
					httpConn.setRequestProperty("Content-length", "" + requestStringBytes.length);
					httpConn.setRequestProperty("Content-Type", "application/octet-stream");
					httpConn.setRequestProperty("Connection", "Keep-Alive");
					httpConn.setRequestProperty("Charset", "UTF-8");				
					
					OutputStream outputStream=httpConn.getOutputStream();
					Log.i("upload", "httpConnection established");
					outputStream.write(requestStringBytes);
					outputStream.flush();
					outputStream.close();	
					
					int responseCode = httpConn.getResponseCode();
					if (HttpURLConnection.HTTP_OK == responseCode){
						Log.i("upload", "httpConnection responsecode ok");
					}
					InputStreamReader in = new InputStreamReader(httpConn.getInputStream());
					BufferedReader buffer = new BufferedReader(in);
					String result = "";
					String inputLine = null;
					while(((inputLine=buffer.readLine())!=null)){
						result+=inputLine;
					}
					buffer.close();
					httpConn.disconnect();
					
					if(result!=null&&result.length()>0){
						String code = "";//返回的档案编码
						Log.i("upload", "result="+result);
						JSONObject json = new JSONObject(result);
						if(json.getString("verify").equals("1")){
							code = json.getString("record_code");
							Log.i("upload", "code="+code);
							
							updateHealthRecord(code);
							message.what = 11;//提交成功,并得到档案编号
						}
						else{
							message.what = 12;
						}
					}
					else{
						message.what = 12;//未成功提交
						Log.e("upload", "upload failed...");
					}
				} 
				catch (Exception ex){
					message.what = 12;//未成功提交
					Log.e("upload", "upload failed...");
					ex.printStackTrace();
				}
				
				mhandler.sendMessage(message);
			}
		}
		
	}
	
	/**
	 * 根据recordid更新数据库
	 * @param recordid 档案编号
	 */
	private void updateHealthRecord(String recordid) {
		// TODO Auto-generated method stub
		int preId = this.profileid;
		String id = recordid;//18位
		String def_id = this.getSharedPreferences(USERINFO, Context.MODE_PRIVATE).getString("area_code","");
		String s = id.replace(def_id, "");
		int postId = Integer.parseInt(s);
		Log.i("update", "preId="+preId);
		Log.i("update", "postId="+postId);
		this.profileid = postId;
		
		//封面
		HereTipa ht=new HereTipa(getBaseContext());
		ht.selectHereTipa(preId);
		ht.setHeti_profileid(postId);
		ht.setHeti_here_id(recordid);
		ht.updateHereTipa(preId);
		
		//基本信息表
		PersonInfo pi = new PersonInfo(getBaseContext());
		pi.selectPersonInfo(preId);
		pi.setPein_profile_id(postId);
		pi.updatePersonInfo(preId);
		
		//体检表
		String where = HETE_COLUMN1 + "=" + profileid ;
		Cursor cursor = getContentResolver().query(CONTENT_URI_TB5, null, where, null, null);
		HealthTest htt=new HealthTest(getBaseContext());
		HospitalHistory hh = new HospitalHistory(getBaseContext());
		SickbedHistory sh = new SickbedHistory(getBaseContext());
		MedicateRecord mr = new MedicateRecord(getBaseContext());
		NonimmuneVaccineHistory nvh = new NonimmuneVaccineHistory(getBaseContext());
		for(int i=1;i<=cursor.getCount();i++){
			htt.selectHealthTest(preId, i);
			htt.setHete_profileid(postId);
			htt.setHete_testid(i);
			htt.updateHealthTest(preId, i);
			
			//住院史---限填2项
			hh.selectHospitalHistory(preId, i, 1);
			hh.setHohi_profileid(postId);
			hh.setHohi_testid(i);
			hh.setHohi_id(1);
			hh.updateHospitalHistory(preId, i, 1);
			hh.selectHospitalHistory(preId, i, 2);
			hh.setHohi_profileid(postId);
			hh.setHohi_testid(i);
			hh.setHohi_id(2);
			hh.updateHospitalHistory(preId, i, 2);
			//病床史---限填2项
			sh.selectSickbedHistory(preId, i, 1);
			sh.setSihi_profileid(postId);
			sh.setSihi_testid(i);
			sh.setSihi_id(1);
			sh.updateSickbedHistory(preId, i, 1);
			sh.selectSickbedHistory(preId, i, 2);
			sh.setSihi_profileid(postId);
			sh.setSihi_testid(i);
			sh.setSihi_id(2);
			sh.updateSickbedHistory(preId, i, 2);
			//吃药信息---限填6项
			mr.selectMedicateRecord(preId, i, 1);
			mr.setMere_profileid(postId);
			mr.setMere_testid(i);
			mr.setMere_id(1);
			mr.updateMedicateRecord(preId, i, 1);
			mr.selectMedicateRecord(preId, i, 2);
			mr.setMere_profileid(postId);
			mr.setMere_testid(i);
			mr.setMere_id(2);
			mr.updateMedicateRecord(preId, i, 2);
			mr.selectMedicateRecord(preId, i, 3);
			mr.setMere_profileid(postId);
			mr.setMere_testid(i);
			mr.setMere_id(3);
			mr.updateMedicateRecord(preId, i, 3);
			mr.selectMedicateRecord(preId, i, 4);
			mr.setMere_profileid(postId);
			mr.setMere_testid(i);
			mr.setMere_id(4);
			mr.updateMedicateRecord(preId, i, 4);
			mr.selectMedicateRecord(preId, i, 5);
			mr.setMere_profileid(postId);
			mr.setMere_testid(i);
			mr.setMere_id(5);
			mr.updateMedicateRecord(preId, i, 5);
			mr.selectMedicateRecord(preId, i, 6);
			mr.setMere_profileid(postId);
			mr.setMere_testid(i);
			mr.setMere_id(6);
			mr.updateMedicateRecord(preId, i, 6);
			//非免疫预防接种---限填3项
			nvh.selectNonimmuneVaccineHistory(preId, i, 1);
			nvh.setNovh_profileid(postId);
			nvh.setNovh_testid(i);
			nvh.setNovh_id(1);
			nvh.updateNonimmuneVaccineHistory(preId, i, 1);
			nvh.selectNonimmuneVaccineHistory(preId, i, 2);
			nvh.setNovh_profileid(postId);
			nvh.setNovh_testid(i);
			nvh.setNovh_id(2);
			nvh.updateNonimmuneVaccineHistory(preId, i, 2);
			nvh.selectNonimmuneVaccineHistory(preId, i, 3);
			nvh.setNovh_profileid(postId);
			nvh.setNovh_testid(i);
			nvh.setNovh_id(3);
			nvh.updateNonimmuneVaccineHistory(preId, i, 3);
		}
		
		ModuleSelect ms=new ModuleSelect(getBaseContext());
		ms.selectModuleSelect(preId);
		ms.setMose_profile_id(postId);
		ms.setMose_health_record_id(1);
		ms.updateModuleSelect(preId);
		
	}
	
	public class myThread extends Thread{  
		private Handler handler;
		private String str;
		private int state;
		public myThread(Handler handler,String s,int state){
			this.handler=handler;
			this.str=s;
			this.state=state;
		}
		
		public void run(){  
	        try  
	        {   
	        	Looper.getMainLooper();
	        	sleep(200); 
	        	Message msg = handler.obtainMessage(); 
	        	if(state==1){
	        		openChild();
	        		msg.what=1;
	        	}
	        	else if(state==2){
	        		phfv.initWeidget();
	        		pi1.findWeidget();
	        		pi2.findWeidget();
	        		ht_1.findViewsById();
	        		ht_1.fetchData();
	        		ht_2.findViewsById();
	        		ht_2.fetchData();
	        		ht_3.findViewsById();
	        		ht_3.fetchData();
	        		ht_4.findViewsById();
	        		ht_4.fetchData();
	        		ht_5.findViewsById();
	        		ht_5.fetchData();
	        		ht_6.findViewsById();
	        		ht_6.fetchData();
	        		jzv.initWeidget();
	        		hzv.initWeidget();
	        		msg.what=2;
	        	}
	        	else if(state==3){
	        		openModuleWomen();
	        		msg.what=3;
	        	}
	        	else if(this.state==4){
	        		insertJieZhenRecord();
	        		msg.what=4;
	        	}
	        	else if(this.state==5){
	        		insertHuiZhenRecord();
	        		msg.what=5;
	        	}
	        	else if(this.state==7){
	        		openModuleMental();
	        		msg.what=7;
	        	}
	        	else if(this.state==8){
	        		openModuleVaccine();
	        		msg.what=8;
	        	}
	        	else if(this.state==9){
	        		openModuleDiabet();
	        		msg.what=9;
	        	}
	        	else if(this.state==10){
	        		deleteProfile(profileid);
	        		msg.what=10;
	        	}
	        	handler.sendMessage(msg); 
			}  
		    catch (Exception e)  
		    {  
		        e.printStackTrace();  
		    }  
		}  
	}
	
	private final Handler handler = new Handler(Looper.getMainLooper()) {
    	public void handleMessage(Message msg) { // 处理Message，更新ListView 
    		if(msg.what==1){
    			if(father==MODULE_FATHER){
					Intent editprofile = new Intent();
					Bundle bd = new Bundle();
					bd.putInt("Profile_id", profileid);//待编辑档案的ID
					bd.putInt("father", MODULE_CHILD);
					bd.putInt("call", MODULE_PEOPLE_HEALTH);
					editprofile.putExtras(bd);
					editprofile.setClass(PeopleScrollActivity.this, ChildScrollActivity.class);
					startActivity(editprofile);
					overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
				}
				else if(father==MODULE_CHILD){
					
						Intent editprofile = new Intent();
						Bundle bd = new Bundle();
						bd.putInt("Profile_id", profileid);//待编辑档案的ID
						bd.putInt("father", MODULE_CHILD);
						bd.putInt("call", call);
						editprofile.putExtras(bd);
						editprofile.setClass(PeopleScrollActivity.this, ChildScrollActivity.class);
						startActivity(editprofile);
						overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
						finish();
				}	
    			mpDialog.cancel();
    		}
    		else if(msg.what==2){
    			phfv.initView();
    			pi1.selectData();
    			pi1.addToView();
    			pi1.initView();
    			pi2.selectData();
    			pi2.addToView();
    			pi2.initView();
    			ht_1.initViews();
        		ht_1.setMyView();
    			ht_2.initViews();
        		ht_2.setMyView();
    			ht_3.initViews();
        		ht_3.setMyView();
    			ht_4.initViews();
        		ht_4.setMyView();
    			ht_5.initViews();
        		ht_5.setMyView();
    			ht_6.initViews();
        		ht_6.setMyView();
    			jzv.initView();
    			hzv.initView();
    			ht=new HereTipa(PeopleScrollActivity.this);
    			ht.selectNameAndCode(profileid);
    			
    			initModuleList();
    			
    			mpDialog.cancel();
    		}
    		else if(msg.what==3){
    			if(father==MODULE_FATHER){
					Intent editprofile = new Intent();
					Bundle bd = new Bundle();
					bd.putInt("Profile_id", profileid);//待编辑档案的ID
					bd.putInt("father", MODULE_CHILD);
					bd.putInt("call", MODULE_PEOPLE_HEALTH);
					editprofile.putExtras(bd);
					editprofile.setClass(PeopleScrollActivity.this, PregnantScrollActivity.class);
					startActivity(editprofile);
					overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
				}
				else if(father==MODULE_CHILD){
					
						Intent editprofile = new Intent();
						Bundle bd = new Bundle();
						bd.putInt("Profile_id", profileid);//待编辑档案的ID
						bd.putInt("father", MODULE_CHILD);
						bd.putInt("call", call);
						editprofile.putExtras(bd);
						editprofile.setClass(PeopleScrollActivity.this, PregnantScrollActivity.class);
						startActivity(editprofile);
						overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
						finish();
				}	
    			mpDialog.cancel();
    		}
    		else if(msg.what==4){
    			adapter.notifyDataSetChanged();
    			mpDialog.cancel();
    		}
    		else if(msg.what==5){
    			adapter.notifyDataSetChanged();
    			mpDialog.cancel();
    		}
    		else if(msg.what==6){
    			ht_1.initViews();
    			ht_2.initViews();
    			ht_3.initViews();
    			ht_4.initViews();
    			ht_5.initViews();
    			ht_6.initViews();
    			
    			initExList();
    			mpDialog.cancel();
    			Toast.makeText(PeopleScrollActivity.this, "创建新体检表成功！", Toast.LENGTH_LONG).show();
    		}
    		else if(msg.what==7){
    			if(father==MODULE_FATHER){
					Intent editprofile = new Intent();
					Bundle bd = new Bundle();
					bd.putInt("Profile_id", profileid);//待编辑档案的ID
					bd.putInt("father", MODULE_CHILD);
					bd.putInt("call", MODULE_PEOPLE_HEALTH);
					editprofile.putExtras(bd);
					editprofile.setClass(PeopleScrollActivity.this, MentalerDetails.class);
					startActivity(editprofile);
					overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
				}
				else if(father==MODULE_CHILD){
					
						Intent editprofile = new Intent();
						Bundle bd = new Bundle();
						bd.putInt("Profile_id", profileid);//待编辑档案的ID
						bd.putInt("father", MODULE_CHILD);
						bd.putInt("call", call);
						editprofile.putExtras(bd);
						editprofile.setClass(PeopleScrollActivity.this, MentalerDetails.class);
						startActivity(editprofile);
						overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
						finish();
				}	
    			mpDialog.cancel();
    		}
    		else if(msg.what==8){
    			if(father==MODULE_FATHER){
					Intent editprofile = new Intent();
					Bundle bd = new Bundle();
					bd.putInt("Profile_id", profileid);//待编辑档案的ID
					bd.putInt("father", MODULE_CHILD);
					bd.putInt("call", MODULE_PEOPLE_HEALTH);
					editprofile.putExtras(bd);
					editprofile.setClass(PeopleScrollActivity.this, VaccinationScrollActivity.class);
					startActivity(editprofile);
					overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
				}
				else if(father==MODULE_CHILD){
					
						Intent editprofile = new Intent();
						Bundle bd = new Bundle();
						bd.putInt("Profile_id", profileid);//待编辑档案的ID
						bd.putInt("father", MODULE_CHILD);
						bd.putInt("call", call);
						editprofile.putExtras(bd);
						editprofile.setClass(PeopleScrollActivity.this, VaccinationScrollActivity.class);
						startActivity(editprofile);
						overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
						finish();
				}	
    			mpDialog.cancel();
    		}
    		else if(msg.what==9){
    			if(father==MODULE_FATHER){
					Intent editprofile = new Intent();
					Bundle bd = new Bundle();
					bd.putInt("Profile_id", profileid);//待编辑档案的ID
					bd.putInt("father", MODULE_CHILD);
					bd.putInt("call", MODULE_PEOPLE_HEALTH);
					editprofile.putExtras(bd);
					editprofile.setClass(PeopleScrollActivity.this, DiabeterDetails.class);
					startActivity(editprofile);
					overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
				}
				else if(father==MODULE_CHILD){
					
						Intent editprofile = new Intent();
						Bundle bd = new Bundle();
						bd.putInt("Profile_id", profileid);//待编辑档案的ID
						bd.putInt("father", MODULE_CHILD);
						bd.putInt("call", call);
						editprofile.putExtras(bd);
						editprofile.setClass(PeopleScrollActivity.this, DiabeterDetails.class);
						startActivity(editprofile);
						overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
						finish();
				}	
    			mpDialog.cancel();
    		}
    		else if(msg.what==10){
    			Log.i("delete", "delete success!");
				Intent intent = new Intent(PeopleScrollActivity.this, ShelfActivity.class);
				Bundle bundle = new Bundle();
				bundle.putString("delete_name", pi1.getName());
				bundle.putInt("delete_id", profileid);
				intent.putExtras(bundle);
    			setResult(RESULT_DELETE,intent);
				finish();
				overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
				mpDialog.cancel();
    		}
    		else if(msg.what==11){//提交个人信息完成
				Log.i("upload", "upload success");
				
				mpDialog.cancel();
				Toast.makeText(PeopleScrollActivity.this, "提交成功", Toast.LENGTH_LONG).show();
    		}
    		else if(msg.what==12){//提交个人信息失败
				Log.i("upload", "upload failed");
				mpDialog.cancel();
				Toast.makeText(PeopleScrollActivity.this, "提交失败", Toast.LENGTH_LONG).show();
    		}
    		
    	} 
    };
    
    public void openChild(){
    	ModuleSelect ms=new ModuleSelect(this);
		ms.selectModuleSelect(profileid);
		ms.setMose_0_6_child_health_id(1); 
		ms.updateModuleSelect(profileid);
		NewBornChild nbc=new NewBornChild(this);
		nbc.setBoch_profileid(profileid);
		nbc.insertNewBornChild();
		OneChild oc=new OneChild(this);
		oc.setOnch_profileid(profileid);
		oc.setOnch_state(1);
		oc.insertOneChild();
		oc.setOnch_state(2);
		oc.insertOneChild();
		oc.setOnch_state(3);
		oc.insertOneChild();
		oc.setOnch_state(4);
		oc.insertOneChild();
		TwoChild tc=new TwoChild(this);
		tc.setTwch_profileid(profileid);
		tc.setTwch_state(1);
		tc.insertTwoChild();
		tc.setTwch_state(2);
		tc.insertTwoChild();
		tc.setTwch_state(3);
		tc.insertTwoChild();
		tc.setTwch_state(4);
		tc.insertTwoChild();
		ThreeChild thc=new ThreeChild(this);
		thc.setTtch_profileid(profileid);
		thc.setTtch_state(1);
		thc.insertThreeChild();
		thc.setTtch_state(2);
		thc.insertThreeChild();
		thc.setTtch_state(3);
		thc.insertThreeChild();
		thc.setTtch_state(4);
		thc.insertThreeChild();
    }
    
    public void openModuleWomen(){
    	ModuleSelect ms=new ModuleSelect(this);
		
		ms.selectModuleSelect(profileid);
		ms.setMose_maternal_health_id(1);
		ms.updateModuleSelect(profileid);
		FirstPrenatalVisit fpv=new FirstPrenatalVisit(this);
		fpv.setFipv_id(profileid);
		fpv.insertFirstPrenatalVisit();
		PrenatalVisit pv=new PrenatalVisit(PeopleScrollActivity.this);
		pv.setPrvi_id(profileid);
		pv.setPrvi_times(2);
		pv.insertPrenatalVisit();
		pv.setPrvi_id(profileid);
		pv.setPrvi_times(3);
		pv.insertPrenatalVisit();
		pv.setPrvi_id(profileid);
		pv.setPrvi_times(4);
		pv.insertPrenatalVisit();
		pv.setPrvi_id(profileid);
		pv.setPrvi_times(5);
		pv.insertPrenatalVisit();
		PostnatalVisit post=new PostnatalVisit(PeopleScrollActivity.this);
		post.setPovi_id(profileid);
		post.insertPostnatalVisit();
		LastPostnatalCheck lpc=new LastPostnatalCheck(PeopleScrollActivity.this);
		lpc.setLapc_id(profileid);
		lpc.insertLastPostnatalCheck();
		
    }
    
    public void openModuleMental(){
    	ModuleSelect ms=new ModuleSelect(this);
		
		ms.selectModuleSelect(profileid);
		ms.setMose_mental_id(1);
		ms.updateModuleSelect(profileid);
		
		MentalerInfo mi = new MentalerInfo(this);
		mi.setMein_profileid(profileid);
		mi.insertMentalerInfo();
		VisitMentals vm = new VisitMentals(this);
		vm.setVime_profileid(profileid);
		vm.setVime_times(1);
		vm.insertVisitMentals();
    }
    
    public void openModuleDiabet(){
    	ModuleSelect ms=new ModuleSelect(this);
		
		ms.selectModuleSelect(profileid);
		ms.setMose_diabet2_id(1);
		ms.updateModuleSelect(profileid);
		
		DiabetService ds = new DiabetService(this);
		ds.setDise_profileid(profileid);
		ds.insertDiabetService();
    }
    
    public void openModuleVaccine(){
    	ModuleSelect ms=new ModuleSelect(this);
		
		ms.selectModuleSelect(profileid);
		ms.setMose_vaccinate_id(1);
		ms.updateModuleSelect(profileid);
		
		VaccinationCard vc = new VaccinationCard(this);
		vc.setVaca_profile_id(profileid);
		vc.insertVaccinationCard();
		
		VaccinationRecord vr = new VaccinationRecord(this);
		vr.setVare_profile_id(profileid);
		vr.insertVaccinationRecord();
    }
    
    public void setBtnVisible(){
    	switch(pageIndex){
    	case 0:
    		rightBtn0.setVisibility(View.INVISIBLE);
    		break;
    	case 1:
    	case 2:
    		rightBtn0.setText("修改");
    		rightBtn0.setVisibility(View.VISIBLE);
    		break;
    	case 3:
    	case 4:
    	case 5:
    	case 6:
    	case 7:
    	case 8:
    	case 9:
    	case 10:
    		rightBtn0.setText("新建");
    		rightBtn0.setVisibility(View.VISIBLE);
    		break;
    	}
    }
    
    public void insertJieZhenRecord(){
    	jzr.setThre_profileid(profileid);
    	System.out.println("this.jiezhen_num="+this.jiezhen_num);
    	jzr.setThre_state(this.jiezhen_num+1);
    	jzr.insertJieZhenRecord();
    	this.jiezhen_num++;
    	HashMap<String, String> child3Data11= new HashMap<String, String>();
		child3Data11.put(FATHERACCOUNT, "第"+(this.jiezhen_num)+"次接诊记录表");
		child3Data11.put(CHILDACCOUNT,"日期:"+jzr.getThre_date());
		cashAccount1.add(child3Data11);
    }
    
    public void insertHuiZhenRecord(){
    	hzr.setCore_profileid(profileid);
    	hzr.setCore_state(this.huizhen_num+1);
    	hzr.insertHuiZhenRecord();
    	this.huizhen_num++;
    	HashMap<String, String> child3Data11= new HashMap<String, String>();
		child3Data11.put(FATHERACCOUNT, "第"+(this.jiezhen_num)+"次接会记录表");
		child3Data11.put(CHILDACCOUNT,"日期:"+hzr.getCore_date());
		cashAccount2.add(child3Data11);
    }

}
